package com.servlet;

import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;

import com.dao.WorkingMapper;
import com.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

@WebServlet(urlPatterns = { "/User" }, name = "User")
public class UserServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String title=request.getParameter("title");
		SqlSession sqlSession = null;
		int count=0;

		try {
			sqlSession=MybatisUtil.createSqlSession();
			count=sqlSession.getMapper(WorkingMapper.class).getTitleCount(title);

		}catch (Exception e){
			e.printStackTrace();
		}finally {
			MybatisUtil.closeSqlSession(sqlSession);
		}
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		out.print(count>0);
		out.flush();
		out.close();
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		this.doGet(request, response);
	}
}
